<div class="main-content" id="main-content">
	<div class="sub-content">	
		<div class="top-header">
			<h1>Change Password</h1>
		</div>
		<div class="adding_form">
			<div class="adding_list">
				<label>Old Password:</label>
					<input type="password" name="oldpwd" id="oldpwd" placeholder="Enter your old password"/>
			</div>
			<div class="adding_list">
				<label>New Password:</label>
				<input type="password" name="newpwd" id="newpwd" placeholder="Enter your new password"/>
			</div>
			<div class="adding_list">
				<label>Confirm Password:</label>
				<input type="password" name="confirm-pwd" id="confirm-pwd" placeholder="Enter your confirm password"/>
			</div>
			<div class="adding_list">
				<div class="botton_btns">
					<ul>
						<li><button onclick="return changePassword();">Submit</button></li>
						<li><button>Back</button></li>
					</ul>
				</div>
			</div><br/>		
			<span id="confirmerrormsg1" style="margin-left:70px;color:red"><span>			
			<span id="confirmerrormsg" style="margin-left:70px;color:green"><span>
			<? if(isset($_SESSION['superadmin'])){
				$userid=$_SESSION['superadmin']['user_id'];
			}else if(isset($_SESSION['admin'])){
				$userid=$_SESSION['admin']['user_id'];
			}else{
				$userid='';
			}?>
			<input type="hidden" id="hiduserid" name="hiduserid" value="<?echo $userid;?>">
		</div>
	</div>
</div>
<!--End-->
<script>
	function changePassword(){		
		var flag=true;
		var userId=$("#hiduserid").val();		
		var oldpasswrd=$("#oldpwd").val();		
		var passwrd=$("#newpwd").val();
		var cnfpwrd=$("#confirm-pwd").val();		
		if(passwrd==""&& cnfpwrd==""){
			$("#confirmerrormsg").html('Please Enter Your New Password!');
			flag=false;
			$("#newpwd").focus();
		}
		if(oldpasswrd==""){
			$("#confirmerrormsg").html('Please Enter Your Old Password!');
			flag=false;
			$("#oldpwd").focus();
		}	
		if(flag==false){ 
				return false;
		}else{					
			if(passwrd==cnfpwrd){
				$.ajax({
					type:'POST',
					url:   '/admin/checkPassword',
					data:{oldpasswrd:oldpasswrd,userId:userId},
					success: function(data){
						if(data.output=='success'){	
							$.ajax({
								type:'POST',
								url: '/admin/changepassword',
								data:{cnfpwrd:cnfpwrd,userId:userId},
								success: function(data){
									//var path="<?echo $_SESSION['admin']['display_name'] .'-'.$_SESSION['admin']['user_id'].'-'.$_SESSION['admin']['user_type'];?>";
									$("#confirmerrormsg").html('Your Password Successfully Updated!');
									window.location='/admin/index';
								}
							});					
						}else{
							$("#confirmerrormsg").html('You Entered Old Password Is Wrong');
						}
					}
				});					
			}else{
				$("#confirmerrormsg").html('Your Confirm Password do not match!');
				$("#confirm-pwd").focus();
			}
		}		
	}	
</script>